package com.fuyao.cloud.daemon.quartz.task;

import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.StrUtil;
import com.fuyao.cloud.admin.api.feign.RemoteUserInfoService;
import com.fuyao.cloud.common.core.constant.SecurityConstants;
import com.fuyao.cloud.daemon.quartz.constants.CloudQuartzEnum;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestHeader;

/**
 * 同步oa数据
 *
 * @author lyhil
 * @date 2022年5月5日
 */
@Slf4j
@Component("syncOaDataTask")
@AllArgsConstructor
public class SpringBeanSyncOaDataTask {

    private final RemoteUserInfoService userInfoService;

    /**
     * 执行方法 同步OA数据
     *
     * @param param 参数 type|jobName 类型|定时任务名称
     */
    @SneakyThrows
    public String run(String param) {
        log.info(" SpringBeanSyncOaDataTask param:{}:", param);
        log.info(" run date start time :{}", LocalDateTimeUtil.now());

        try {
            this.userInfoService.syncOaData(SecurityConstants.FROM_IN);
        }catch (Exception e){
            log.error("执行同步oa数据异常：" + e.getMessage());
            return CloudQuartzEnum.JOB_LOG_STATUS_FAIL.getType();
        }
        log.info(" run date end time :{}", LocalDateTimeUtil.now());
        return CloudQuartzEnum.JOB_LOG_STATUS_SUCCESS.getType();
    }
}
